package com.swh.xbsc.controller;


import com.swh.xbsc.entity.Result;
import com.swh.xbsc.util.EmailUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@RestController
@RequestMapping("/mapper/article")
public class EmailController {


//    protected Result sendEmail(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//
//        try {
//            String email = req.getParameter("email");
//
//            //纯数字的验证码
//            int result = (int) ((Math.random() + 1) * 1000);
//            String code = String.valueOf(result);
//
//            //包含数字和英文的验证码
//            String ZiMu = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGJKLZXCVBNM1234567890";
////            String code = "";
////            Random random = new Random();
////            for (int i = 0; i < 4; i++) {
////                int index = random.nextInt(ZiMu.length());
////                char c = ZiMu.charAt(index);
////                code += c;
////            }
//
//
//            //存session
//            HttpSession session = req.getSession();
//            session.setAttribute("code", code);
//            session.setMaxInactiveInterval(60);
//
//            EmailUtil.sendEmail(email, code);
//
//            return new Result(true, "发送成功", null);
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//
//            return new Result(false, "发送失败", null);
//        }
//    }

}


